package com.slz3.business.module.drawManagement.draFreeLottery.steward;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.enums.YNFlag;
import com.slz3.business.frame.functions.Add;
import com.slz3.business.frame.functions.Modify;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.response.RR;
import com.slz3.business.frame.steward.Steward;
import com.slz3.business.frame.util.VE;
import com.slz3.business.module.drawManagement.draFreeLottery.domain.DraFreeLottery;
import com.slz3.business.module.drawManagement.draFreeLottery.domain.DraFreeLotteryCondition;
import com.slz3.business.module.drawManagement.draIntegralLottery.domain.DraIntegralLottery;
import com.slz3.business.module.drawManagement.draIntegralLottery.domain.DraIntegralLotteryCondition;
import org.springframework.web.reactive.function.server.ServerRequest;

import java.time.LocalDateTime;
import java.util.List;


public class DraFreeLotteryResUnsafeValid {

    public static boolean add(ServerRequest req, DraFreeLottery draFreeLottery) {
        Steward.constraintViolations(req, draFreeLottery, Add.class);
        return RR.hasResErr(req);
    }

    public static boolean delete(ServerRequest req, DraFreeLotteryCondition draFreeLotteryCondition) {
        if (VE.isEmpty(draFreeLotteryCondition.getUuidList())) {
            RR.resDetail(req).put("uuidList", "must not null");
        } else if (draFreeLotteryCondition.getUuidList().size() > 800) {
            RR.resDetail(req).put("uuidList", "uuidList max size is 800");
        }
        return RR.hasResErr(req);
    }

    static boolean modify(ServerRequest req, DraFreeLottery draFreeLottery) {
        Steward.constraintViolations(req, draFreeLottery, Modify.class);
        return RR.hasResErr(req);
    }

    public static boolean list(ServerRequest req) {
        return RR.hasResErr(req);
    }

    public static boolean info(ServerRequest req) {
        if (VE.isEmpty(req.queryParam("uuid").orElse(null))) {
            RR.resDetail(req).put("uuid", "must not null");
        }
        return RR.hasResErr(req);
    }

    public static boolean choice(ServerRequest req) {
        return RR.hasResErr(req);
    }

    public static boolean auditSubmit(ServerRequest req, DraFreeLotteryCondition draFreeLotteryCondition) {
        if (VE.isEmpty(draFreeLotteryCondition.getUuidList())) {
            RR.resDetail(req).put("uuidList", "must not null");
        } else if (draFreeLotteryCondition.getUuidList().size() > 800) {
            RR.resDetail(req).put("uuidList", "uuidList max size is 800");
        }
        return RR.hasResErr(req);
    }

    public static boolean audit(ServerRequest req, DraFreeLotteryCondition draFreeLotteryCondition) {
        if (VE.isEmpty(draFreeLotteryCondition.getUuidList())) {
            RR.resDetail(req).put("uuidList", "must not null");
        } else if (draFreeLotteryCondition.getUuidList().size() > 800) {
            RR.resDetail(req).put("uuidList", "uuidList max size is 800");
        }
        return RR.hasResErr(req);
    }

    public static boolean auditReject(ServerRequest req, DraFreeLotteryCondition draFreeLotteryCondition) {
        if (VE.isEmpty(draFreeLotteryCondition.getUuidList())) {
            RR.resDetail(req).put("uuidList", "must not null");
        } else if (draFreeLotteryCondition.getUuidList().size() > 800) {
            RR.resDetail(req).put("uuidList", "uuidList max size is 800");
        }
        return RR.hasResErr(req);
    }

    public static boolean usingEnable(ServerRequest req, DraFreeLotteryCondition draFreeLotteryCondition) {
        if (VE.isEmpty(draFreeLotteryCondition.getUuidList())) {
            RR.resDetail(req).put("uuidList", "must not null");
        } else if (draFreeLotteryCondition.getUuidList().size() > 800) {
            RR.resDetail(req).put("uuidList", "uuidList max size is 800");
        }
        return RR.hasResErr(req);
    }

    public static boolean usingDisable(ServerRequest req, DraFreeLotteryCondition draFreeLotteryCondition) {
        if (VE.isEmpty(draFreeLotteryCondition.getUuidList())) {
            RR.resDetail(req).put("uuidList", "must not null");
        } else if (draFreeLotteryCondition.getUuidList().size() > 800) {
            RR.resDetail(req).put("uuidList", "uuidList max size is 800");
        }
        return RR.hasResErr(req);
    }
  /*  public static boolean lottery(ServerRequest req, DraFreeLotteryCondition draFreeLotteryCondition) {
        List<DraFreeLottery> draFreeLotteryList = Services.draFreeLottery.findAllByUuids(draFreeLotteryCondition.getUuidList());
        if (draFreeLotteryList.stream().filter(item -> {
//            System.err.println(ValidFlag.isDel(item.getValidFlag()));
//            System.err.println(item.getSerGoodsDrawEndDate() == null);
//            System.err.println(item.getSerGoodsDrawNumber() == null);
//            System.err.println(item.getSerGoodsDrawEndDate().isAfter(LocalDateTime.now()));
//            System.err.println(YNFlag.isYes(item.getSerAlreadyLotteryEnum()));
//            System.err.println(item.getSerGoodsDrawNumber().length() == 0);
                    return ValidFlag.isDel(item.getValidFlag())
                            || item.getSerGoodsDrawEndDate() == null
//                || item.getSerAlreadyLotteryEnum() == null
                            || item.getSerGoodsDrawNumber() == null

                            || item.getSerGoodsDrawEndDate().isAfter(LocalDateTime.now())
                            || YNFlag.isYes(item.getSerAlreadyLotteryEnum())
                            || item.getSerGoodsDrawNumber().length() == 0;
                }
        ).count() > 0) {
            RR.resDetail(req).put(RR.SAFE_VALID, "不能对【被删除】【未结束】【已开奖】和【无中奖号码】的记录进行开奖！");
        } else {
            req.attributes().put(RR.RELAY_SAFE_VALID, draFreeLotteryList);
        }
        return RR.hasResErr(req);
    }*/
    public static boolean lottery(ServerRequest req, DraFreeLotteryCondition draFreeLotteryCondition) {
        if (VE.isEmpty(draFreeLotteryCondition.getUuidList())) {
            RR.resDetail(req).put("uuidList", "must not null");
        } else if (draFreeLotteryCondition.getUuidList().size() > 800) {
            RR.resDetail(req).put("uuidList", "uuidList max size is 800");
        }
        return RR.hasResErr(req);
    }
}
